/**
 * Created by hcadmin on 16/3/17.
 */
define([
    "jquery",
    "IO",
    "bootbox"
], function($,IO,bootbox) {
    $(function () {
        var grid;
        var course_id = $("#course_id").val();
        var lecture_id = $("#lecture_id").val();
        //每列数据列性
        var columns = [
            {
                title: '出现时间',
                dataIndex: 'create_date',
                dataSource: function (data, datarow, gridobj, current_column) {
                    var min = parseInt(data[datarow].time/60);
                    var sec = data[datarow].time%60;
                    if (min<10) {
                        min = '0' + min;
                        if (min < 1)
                            min = '00';
                    }
                    if (sec<10) {
                        sec = '0' + sec;
                        if (sec < 1)
                            sec = '00';
                    }
                    var time = min+':'+sec;
                    return "<span>" + time + "</span>";
                }
            },
            {
                title: '题目',
                dataIndex: 'vocabulary_content',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span>" + data[datarow].question.title + "</span>";
                }
            },
            {
                title: '操作',
                dataIndex: 'action',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span><a href='javascript:void(0)' style='color: red;' class='delete' act_id='"+data[datarow].joint_id
                        +"'>删除</a>&nbsp&nbsp&nbsp&nbsp<a href='/pte/update_time-test?course_id="+course_id+"&lecture_id="+lecture_id+"&joint_id="+data[datarow].joint_id
                        +"'style='color: deepskyblue;'>编辑</a></span>";
                }
            },

        ];


        //数组初始化

        function dataInit() {

            grid = new Grid("/pte/api/course-test?course_id=" + course_id + "&lecture_id=" + lecture_id, $("#table_my_toast"), $("#paging_my_toast"), 1, 10, columns, get_input_param(), 10);

            //初始化
            grid.Init();
        }

        //获取输入框内容
        function get_input_param() {

            var content=$("#question_content").val();
            var param="content=" +content;
            return param;
        }
        dataInit();
        //查询
        $("#query").bind("click", function () {
            dataInit();
        });
    });
    //删除题目
    $(document).on("click",".delete",function(){
        var act_id=$(this).attr("act_id");
        var course_id = $("#course_id").val();
        var lecture_id = $("#lecture_id").val();
        if(act_id){
            bootbox.confirm("确定要删除该题目？",function(result){
                if(result) {
                    IO.get("act/timecourse_test_delete",{act_id:act_id},function(d){
                        bootbox.alert(d.msg,function(){
                            if (d.code == 0) {
                                location.href = '/pte/course-test?course_id='+course_id+'&lecture_id='+lecture_id;
                            }
                        })
                    });
                }
            });
        }
    });

});